<#-- 找回密码第一步 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<base href="${baseURL}">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>找回密码 - ${title}</title>
	<meta name="keywords" content="${keywords}"/>
	<meta name="description" content="${description}"/>
	<link rel="shortcut icon" type="image/x-icon" href="${baseURL}${commonPath}images/favicon.ico" media="screen" />
	<link href="${commonPath}css/common.css" type="text/css" rel="stylesheet" >
	<script language="javascript" src="${commonPath}js/tool.js" type="text/javascript"></script>
	<script language="javascript" src="${commonPath}js/ajax.js" type="text/javascript"></script>
	<script language="javascript" src="${commonPath}js/json2.js" type="text/javascript"></script>
</head>


<script type="text/javascript" language="javascript"> 
//确认提交
	function sureSubmit(objForm){
	
		if(allVerification() == false){
			alert("请填好资料再提交");
			return;
		}
		objForm.submit();
	}
	
	//ajax提交
	function ajaxSubmit(){
		if(allVerification() == false){
			alert("请填好资料再提交");
			return;
		}
		
		var parameter = getParameter();

		post_request(function(value){
			if(value != ""){
				var returnValue = JSON.parse(value);//JSON转为对象
				var jumpUrl = "";
				var success = "false";
				for(var key in returnValue){
					if(key == "success"){	
						success = returnValue[key];	
					}if(key == "jumpUrl"){	
						jumpUrl = returnValue[key];	
					}else if(key == "error"){
						var errorValue = returnValue[key];
						for(var error in errorValue){
							if(error != ""){
								document.getElementById(error+"_error").innerHTML=errorValue[error];	
							}
						}
					}else if(key == "captchaKey"){//显示验证码	
						var captchaKey = returnValue[key];
						if(captchaKey != ""){
							//设置验证码Key
							if(document.getElementById("captchaKey")!= null){
								document.getElementById("captchaKey").value = captchaKey;
								//设置验证码图片
								replaceCaptcha();
							}	
						}
					}
				}
				if(success == "true"){
					//跳转到第二步
					window.location.href = getBasePath()+jumpUrl;
				}
			}	
		},
			"findPassWord/step1?&timestamp=" + new Date().getTime(), true,parameter);
	}
	
	//组装参数
	function getParameter(){
		var parameter = "";
		//令牌标记
		var token = document.getElementById("token").value;
		parameter += "&token="+token;

		var userName = document.getElementById("userName").value;
		if(userName !=""){
			parameter += "&userName="+encodeURIComponent(userName);
		}
		//验证码Key
		var captchaKey = document.getElementById("captchaKey");
		if(captchaKey != null){
			parameter += "&captchaKey="+captchaKey.value;
		}
		//验证码值
		var captchaValue = document.getElementById("captchaValue");
		if(captchaValue != null){
			parameter += "&captchaValue="+captchaValue.value;
		}
		return parameter;
	}
	
	
	
	//验证全部参数
	function allVerification(){
		var isVerification = true;
		if(verification("userName") == false){
			isVerification = false;
		}
		if(verification("captchaValue") == false){
			isVerification = false;
		}
		return isVerification;
	}

	//验证参数
	function verification(field){
	
		if(field == "userName"){//用户名
			var parameter = document.getElementById(field).value;
			if(parameter != null && parameter != ""){
			
				var parameter_trim = trim(parameter);
				if(parameter_trim != ""){
					if(getStringLeng(parameter_trim) < 3){
						document.getElementById(field+"_error").innerHTML = "用户名长度不能小于3位";
						return false;
					}
					if(getStringLeng(parameter_trim) >= 20){
						document.getElementById(field+"_error").innerHTML = "用户名长度不能大于20位";
						return false;
					}
					var pattern =  /^\w+$/;
	            	if(!pattern.test(parameter_trim)) { 
	                	document.getElementById(field+"_error").innerHTML = "用户名只能输入由数字、26个英文字母或者下划线组成";
						return false;
	            	}
				}else{
					document.getElementById(field+"_error").innerHTML = "用户名不能为空";
					return false;
				}
			}else{
			
				document.getElementById(field+"_error").innerHTML = "用户名不能为空";
				return false;
			}
			
		}
		if(field == "captchaValue"){//验证码
			if( document.getElementById("captchaKey") != null){
				var captchaKey = document.getElementById("captchaKey").value;
				var parameter = document.getElementById(field).value;
				if(parameter != ""){
				
					var parameter_trim = trim(parameter);
					if(parameter_trim != ""){
						get_request(function(value){
			            	if(value == "false"){
				            	document.getElementById(field+"_error").innerHTML = "验证码错误";
			            	}
			            },
					 		"userVerification.htm?captchaKey="+captchaKey+"&captchaValue="+parameter_trim+"&timestamp=" + new Date().getTime(), true);
			            	
					}else{
						document.getElementById(field+"_error").innerHTML = "验证码不能为空";
						return false;
					}
				}else{
					document.getElementById(field+"_error").innerHTML = "验证码不能为空";
					return false;
				}
			}
		}
		if(document.getElementById(field+"_error") != null){
			document.getElementById(field+"_error").innerHTML = "";
		}
		return true;
	}
	//更换验证码
	function replaceCaptcha(){
		var captchaKey = document.getElementById("captchaKey").value;
		document.getElementById("captcha").src = "captcha/"+captchaKey+".jpg?" + Math.random(); 
	}
</script> 
<body>
<#-- 引入页头 -->
<@include action="${newPublic_2}"/>
<div class="fixedBottom wrap clearfix">
	<form method="post" autocomplete="off" action="findPassWord/step1">
	<!-- 令牌标记 -->
	<input type="hidden" id="token" name="token" value="${token}">
	
	<div class="findPassWordModule blankTableModule">
	<h2>要找回密码的帐号</h2>
	<table class="blankTable" border="0" cellSpacing="2" cellPadding="0" width="500px" >
		<tbody>
			<tr>
	    		<td width="120px" align="right">用户名： </td>
	    		<td align="left" colspan="2">
	    			<input type="text" id="userName" name="userName" class="formText" size="25" maxlength="20" value="${userName}"/>
	    			<span id="userName_error" class="error">${(error['userName'])!}</span>
	    		</td>
			</tr>
			<tr>
				<td width="120px" align="right">验证码： </td>
				<td width="10px">
					<!-- 验证码Key -->
					<input type="hidden" id="captchaKey" name="captchaKey" value="${captchaKey}">
					<input id="captchaValue" name="captchaValue" type="text" class="formText"  size="7" maxlength="7" autocomplete="off" onBlur="verification(this.id)"/>		
				</td>
				<td align="left">
					<img id="captcha" src="captcha/${captchaKey!}.jpg" onClick="replaceCaptcha()"/>
					<span id="captchaValue_error" class="error">${(error['captchaValue'])!}</span> 
				
				</td>
			</tr>
			<tr>
				<td></td>
				<td colspan="2">
					<span class="submitButton"><INPUT type="button" value="提交" onClick="javascript:sureSubmit(this.form);"></span>
					<!-- 
					<span class="submitButton"><INPUT type="button" value="ajax提交" onClick="javascript:ajaxSubmit();"></span>
					 -->
					<span id="token_error" class="error">${error['token']}</span>  
				</td>
			</tr>
		</tbody>
	</table>
	</div>
	</form>
	<div class="push"><!-- 把div#footer推下去 --></div>
</div>
<#--引入页脚-->
<@include action="${newPublic_3}"/>
</body></html>






